package com.li.test.base;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class AppleDemo2 {
    ArrayBlockingQueue<Integer> ap = new ArrayBlockingQueue<>(5);

    public void add() {

        ap.add(1);

        System.out.println("add值是：" + ap.size() + ".....当前线程：" + Thread.currentThread().getName());

    }

    public void delete() {
        ap.poll();

        System.out.println("delete值是：" + ap.size() + ".....当前线程：" + Thread.currentThread().getName());

    }

    public int[] twoSum(int[] nums, int target) {
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = 0; j < nums.length - 1; j++) {
                if ((nums[i] + nums[j]) == target) {
                    return new int[]{i, j};
                }
            }
        }
        return new int[]{};
    }

    public static void main(String[] args) {

        ThreadPoolExecutor th = new ThreadPoolExecutor(3, 5, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<>());

        AppleDemo2 apple = new AppleDemo2();
        for (int i = 0; i < 1000; i++) {


            th.execute(
                    () -> {
                        apple.add();
                    }
            );
        }
        for (int i = 0; i < 1000; i++) {

            th.execute(() -> {
                apple.delete();
            });

        }
    }
}
